var pro=new Vue({
    el:"#app",
    data:{
        pro_list:[{
            "volume": 10.0,
            "pro_code": "00001",
            "pro_line": "z01",
            "base_price": 54.000,
            "pro_type": "zx",
            "pro_description": "测试",
            "id": 1,
            "pro_attr": "zxvbnm"
        }],
        address:[]
    },
    methods:{
        getProData:function (){
            $.ajax({
                url:host+"/product/getAllInfo",
                type:"get",
                async:true,
                dataType:"json",
                data:{

                },
                success:function (res) {
                    console.log(res)
                    pro.pro_list=[];
                    for(var i=0;i<res.data.length;i++){
                        pro.pro_list.push(res.data[i]);
                    }
                },error:function (){
                    alert("系统繁忙！")
                },
            })

        },
        setNum:function (id,baseprice){
            var numID="#num"+id;
            var priceID="#p"+id;
            $(priceID).text($(numID).val()*baseprice)
        },
        s:function (){
            var $priceClass = $(".price_class");
            var sum=0;
            for(var i=0;i<$priceClass.length;i++){
                var text = $priceClass[i].innerText;
                var n=Number.parseInt(text)
                if(text>0){
                    sum+=n;
                }
            }
            return sum;
        },
        getTotalPrice:function (){
            var val = $("#pro_select").val();
            var num = Math.floor($("#proNum").val());
            if(num<0){
                confirm("数目不能小于0！")
                this.changePro();
                return;
            }
            var sum=0;
            for(var i=0;i<this.pro_list.length;i++){
                if(this.pro_list[i].pro_code==val){
                    sum=this.pro_list[i].base_price*num;
                    break;
                }
            }
            $("#order_price").text(sum);
        },
        changePro:function (){
            var num = $("#proNum").val(1);
            this.getTotalPrice();
        }
    },
    created:function (){
        this.getProData();
    }
})

//提交订单
$("#submint").click(function () {
    //出货仓库
    var selected=document.getElementById("selectA");
    var opt=selected.selectedIndex;
    var code=selected.options[opt].value;

    //产品编号
    var proCode=$("#pro_select").val();

    //配送方式
    var sendWay=document.getElementById("way").innerHTML;

    //起始日期
    var requireDateFrom=document.getElementById("test25").value;

    //截止日期
    var requireDateTo=document.getElementById("test1").value;

    //产品数量
    var proNum=$("#proNum").val();

    //经销商编码
    var dealerCode=window.sessionStorage.getItem("code");

    //备注
    var remark=$("#remark").val();

    //alert(code+"---"+proCode+"--"+proNum+"--"+sendWay+"--"+requireDateFrom+"--"+requireDateTo+"--"+dealerCode+"--"+remark);
    $.ajax({
        url:host+"/stockOrder/subOrder",
        type:"get",
        async:true,
        dataType:"json",
        data:{
            "dealerCode":dealerCode,
            "requireDateFrom":requireDateFrom,
            "requireDateTo":requireDateTo,
            "sendWay":sendWay,
            "storageOutCode":code,
            "storageInCode":"JY001",
            "proNum":proNum,
            "proCode":proCode,
            "remark":remark,
        },
        success:function (res) {
            console.log(res)
            if (res['message']=="提交成功"){
                alert("提交成功");
            }else {
                alert(res['data']);
            }
        },error:function (){
            alert("系统繁忙！")
        },
    })
})